package com.totoro.domain.key;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.totoro.domain.Project;
import com.totoro.domain.Student;


/*
 * 学生报题主键实体类
 */
@Embeddable
public class StudentApplicationKey implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "project_id", referencedColumnName = "id")
	private Project project;// 毕业设计

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "student_id", referencedColumnName = "id")
	private Student student;// 学生

	// 空构造器
	public StudentApplicationKey() {
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	// 复写hashCode方法
	@Override
	public int hashCode() {
		return getStudent().getId() * 13 + getProject().getId();
	}

	// 复写equals方法
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj != null && this.getClass() == obj.getClass()) {
			StudentApplicationKey target = (StudentApplicationKey) obj;
			if (getStudent().getId().equals(target.getStudent().getId())
					&& getProject().getId().equals(target.getProject().getId()))
				return true;
		}
		return false;
	}

}
